import { ObjectPool } from "../../../../../com/gengine/utils/pools/ObjectPool";
import { FlyFootBmp } from "../../mapUI/flyFoot/FlyFootBmp";
import { HTMLUtil } from "../../../../../com/gengine/utils/HTMLUtil";
type int = number;
//class ImgTxt
    
    export  class ImgTxt /* flash.display.Sprite */
    {
        constructor()
        {
            
            this._dic = [];
            mouseEnabled = false;
            return;
        }

        public getLinkIndex(arg1: Object): int
        {
            if (this._dic[arg1] != null) 
            {
                return this._dic[arg1];
            }
            return 0;
        }

        public bulidPic(arg1: string, arg2: int, arg3: Object /* flash.text.TextField */, arg4: string, arg5: Boolean=false, arg6: int=0): int
        {
            var loc3=null;
            var loc4=null;
            this._linkIndex = int(arg1.substr(1));
            this._textField = arg3;
            var loc1=arg3.text.indexOf(arg1, arg2);
            var loc2;
            if ((loc2 = arg3.getCharBoundaries(loc1)) == null) 
            {
                return loc1 + 1;
            }
            if (arg3.getLineIndexOfChar(loc1) > arg3.bottomScrollV) 
            {
                return arg3.text.length;
            }
            if (arg5) 
            {
                arg3.htmlText = arg3.htmlText.replace(arg1, "");
            }
            else 
            {
                (loc3 = ObjectPool.getObject(FlyFootBmp)).update();
                loc3.x = (loc2.x + arg3.x - 1);
                loc3.y = loc2.y - (arg3.scrollV - 1) * arg3.getLineMetrics(0).height + arg3.y - 2;
                loc3.name = this._linkIndex + "";
                this.addChild(loc3);
                loc4 = arg6 != 0 ? "      " : this.replaceStr;
                if (loc2.x <= 10) 
                {
                    loc4 = arg6 != 0 ? "\n    " : "\n" + this.replaceStr;
                }
                else if (loc2.x >= arg3.width - 45) 
                {
                    if (arg3.text.indexOf(arg1) < arg3.text.length - 3) 
                    {
                        loc4 = "\n";
                    }
                }
                arg3.htmlText = arg3.htmlText.replace(arg1, loc4);
            }
            return loc1 + 1;
        }

        public getImgRect(): Object /* flash.geom.Rectangle */
        {
            var loc1=null;
            if (numChildren > 0) 
            {
                loc1 = getChildAt(0) as Object /* flash.display.Sprite */;
                if (loc1 != null) 
                {
                    return new Object /* flash.geom.Rectangle */(loc1.x, loc1.y, loc1.width, loc1.height);
                }
            }
            return new Object /* flash.geom.Rectangle */(x, y, width, height);
        }

        public getTargetRect(arg1: string): Object /* flash.geom.Rectangle */
        {
            if (this._textField == null) 
            {
                return new Object /* flash.geom.Rectangle */(x, y, width, height);
            }
            var loc1=this._textField.text.indexOf(arg1);
            var loc2=this._textField.getCharBoundaries(loc1);
            if (loc2 == null) 
            {
                return this.getImgRect();
            }
            loc2.x = loc2.x + this._textField.x;
            loc2.y = loc2.y + ((-(this._textField.scrollV - 1)) * this._textField.getLineMetrics(0).height + this._textField.y - 2);
            loc2.width = loc2.width * arg1.replace(" ", "").length;
            return loc2;
        }

        public dispose(): void
        {
            var loc1=null;
            this._dic.splice(0);
            this._textField = null;
            while (numChildren > 0) 
            {
                loc1 = getChildAt(0) as FlyFootBmp;
                loc1.dispose();
                removeChild(loc1);
                ObjectPool.disposeObject(loc1);
            }
            return;
        }

        /* internal */ /* const */replaceStr: string=HTMLUtil.addColor("       ", "#ffffff");

        /* internal */ /* var */_textField: Object /* flash.text.TextField */;

        /* internal */ /* var */_dic: Array<any>;

        /* internal */ /* var */_linkIndex: int;
    }
